package cn.exrick.xboot.quartz.jobs;

import cn.exrick.xboot.common.constant.CommonConstant;
import cn.exrick.xboot.common.jiuqiCommon.callAPIUtil.CallApiUtil;
import cn.exrick.xboot.common.utils.PageUtil;
import cn.exrick.xboot.common.utils.jiuqi.utils.CommonUtil;
import cn.exrick.xboot.common.vo.PageVo;
import cn.exrick.xboot.common.vo.SearchVo;
import cn.exrick.xboot.modules.backlogOrFullList.service.IbacklogOrFullListService;
import cn.exrick.xboot.modules.base.entity.Dict;
import cn.exrick.xboot.modules.base.entity.DictData;
import cn.exrick.xboot.modules.base.entity.User;
import cn.exrick.xboot.modules.base.service.DictDataService;
import cn.exrick.xboot.modules.base.service.DictService;
import cn.exrick.xboot.modules.base.service.UserService;
import cn.exrick.xboot.modules.base.service.mybatis.IUserService;
import cn.exrick.xboot.modules.masterdata.server.MasterDataUpdate;
import cn.exrick.xboot.quartz.jobs.distributedLock.entity.Lock;
import cn.exrick.xboot.quartz.jobs.distributedLock.utils.DistributedLockHandler;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.extern.slf4j.Slf4j;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *定时初始化待办数据
 * @Auther: njp
 * @Date: 2020/07/06/10:29
 * @Description:
 */
@Slf4j
@DisallowConcurrentExecution
public class BackLogInitJob implements Job {
    @Autowired
    private DistributedLockHandler distributedLockHandler;
    @Autowired
    private IbacklogOrFullListService ibacklogOrFullListService;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        String nowTime = CommonUtil.getTime().toString();
        Lock lock = new Lock("redisLock:backlogInit", nowTime);
        long timeout = 20 * 1000L;
        //过期时间60秒*6
        long lockExpireTime = 60 * 6 * 1000L;
        if (distributedLockHandler.individualityTryLock(lock, timeout, lockExpireTime)) {
            try {
                synchronized ("") {
                    ibacklogOrFullListService.backlogInitByCall();
                    distributedLockHandler.releaseLock(lock);
                 }
                } catch(Exception e){
                    distributedLockHandler.releaseLock(lock);
                    log.error("BackLogInitJob定时初始化待办数据失败");
                    log.error(e.getMessage());
                }
            }


        }
    }


